<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="pub/top_list2.jsp"%>   
<%
String names = (String) request.getSession().getAttribute("name");
String sql="select password from member where userid=?";
String[] params = new String[1];
params[0] =names;
String password=null;
List<Map<String, Object>> list= db.queryList(sql, params);	
for (Map<String, Object> m : list) {
	password=(String)m.get("password");			
}
if(request.getParameter("pwdn")!=null&&request.getParameter("pwdn")!=""
	&&request.getParameter("pwdn2")!=null&&request.getParameter("pwdn2")!=""){
	MyDB db2 = My.getDb1();
	String sql2 = "update Member set password=?  where userid=?";
	Object[] param2=new Object[2];	
	param2[0] =request.getParameter("pwdn");
	param2[1] =names;	
	db2.executeUpdate(sql2, param2);	
}
%>
<script type="text/javascript">
function fun1(){
	var password="<%=password%>";
	var psw=document.getElementById("pwdo").value;
	if(password!=psw){
		alert("您输入的密码与您原密码不符，请重新输入");
		document.getElementById("pwdo").value="";
	}
}
function fun2(){
	var pwdn=document.getElementById("pwdn").value;
	var pwdo=document.getElementById("pwdo").value;
	if(pwdo==pwdn){
		alert("您输入的新密码与旧密码一样");
		document.getElementById("pwdn").value="";
	}
}
function fun3(){
	var pwdn=document.getElementById("pwdn").value;
	var pwdn2=document.getElementById("pwdn2").value;
	if(pwdn2!=pwdn){
		alert("您两次输入的密码不符，请重新输入");
		document.getElementById("pwdn2").value="";
	}
}
</script>

<body>
	<header class="top-header">
		<a class="icona" href="self.jsp">
			<img src="images/left.png"/>
		</a>
		<h3>修改密码</h3>
	</header>
	
	<div class="login">
		<form action="resetpwd.jsp" method="post">		
			<ul>
				<li>
					<img src="images/login.png"/>
					<input type="password" placeholder="输入原密码" id="pwdo" name="pwdo" onblur="fun1()" required="required"/>
				</li>
				<li>
					<img src="images/password.png"/>
					<input type="password" id="pwdn" name="pwdn"  placeholder="输入新密码" onblur="fun2()" required="required"/>
				</li>
				<li>
					<img src="images/password.png"/>
					<input type="password" id="pwdn2" name="pwdn2" placeholder="输入确认密码"  onblur="fun3()" required="required"/>
				</li>
			</ul>
			<input type="submit" value="立即修改"/>
		</form>
	</div>

</body>
</html>